package com.qf.controller.drugType;

import com.qf.entity.DrugType;
import com.qf.entity.DrugTypeVo;
import com.qf.entity.DrugTypes;
import com.qf.entity.MedicineCategoryVo;
import com.qf.service.drugType.DrugTypeService;
import com.qf.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * --- 永无霸哥 ---
 *
 * @author M.rk
 * @date 2024/12/7 14:07
 * @desc
 */
@RestController
@RequestMapping("/DrugType")
@Slf4j
public class DrugTypeController {

    @Autowired
    DrugTypeService drugTypeService;

    //药品分类
    @GetMapping("/drugClassification")
    public R drugClassification(DrugType drugType) {
        List<DrugTypeVo> drugTypeVos = drugTypeService.drugClassification(drugType);

        if(drugTypeVos!=null){

            return R.ok(drugTypeVos);

        }

        return R.fail();
    }


    //查所有树状结构,使用递归方法
    @GetMapping("/drugTypes")
    public R drugTypes() {
        List<DrugTypes> drugTypes = drugTypeService.selectClass();

        if(drugTypes!=null){

            return R.ok(drugTypes);

        }

        return R.fail();
    }


//    viewDetails

    @GetMapping("/viewDetails")
    public R viewDetails(int id) {
        DrugType drugType = drugTypeService.viewDetails(id);

        if(drugType!=null){

            return R.ok(drugType);

        }

        return R.fail();
    }

}
